package me.panpf.sketch.sample

import android.content.Context
import android.content.pm.PackageManager
import me.panpf.sketch.uri.AndroidResUriModel
import me.panpf.sketch.uri.ApkIconUriModel
import me.panpf.sketch.uri.AppIconUriModel
import me.panpf.sketch.uri.DrawableUriModel
import java.util.*

@Suppress("MemberVisibilityCanBePrivate")
object AssetImage {
    const val TYPE_TEST_JPG = "http://or84z82rx.bkt.clouddn.com/sample.jpg"
    const val TYPE_TEST_PNG = "http://or84z82rx.bkt.clouddn.com/sample.png"
    const val TYPE_TEST_GIF = "http://or84z82rx.bkt.clouddn.com/sample.gif"
    const val TYPE_TEST_WEBP = "http://or84z82rx.bkt.clouddn.com/sample.webp"
    const val TYPE_TEST_BMP = "http://or84z82rx.bkt.clouddn.com/sample.bmp"

    const val HUGE_CHANG_WEI_BO = "http://or84z82rx.bkt.clouddn.com/large_chang_wei_bo.jpg"
    const val HUGE_QMSHT = "http://or84z82rx.bkt.clouddn.com/large_qing_ming_shang_he_tu.jpg"
    const val HUGE_CARD = "http://or84z82rx.bkt.clouddn.com/large_card.png"
    const val HUGE_WORLD_MAP = "http://or84z82rx.bkt.clouddn.com/large_world_map.jpg"

    const val MEI_NV = "asset://mei_nv.jpg"
    const val MASK = "http://or84z82rx.bkt.clouddn.com/mask.png"

    const val CHUNK = "http://nbachina.qq.com/media/img/players/head/260x190/201935.png"
    const val CHUNK2 = "http://static.yingyonghui.com/is/4398/4398642/256i.webp"

    val URI_TEST_ANDR_RES_BY_NAME = AndroidResUriModel.makeUriByName(BuildConfig.APPLICATION_ID, "drawable", "ic_video_play")
    val URI_TEST_ANDR_RES_BY_NAME2 = AndroidResUriModel.makeUriByName(BuildConfig.APPLICATION_ID, "mipmap", "ic_launcher")
    val URI_TEST_ANDR_RES_BY_ID = AndroidResUriModel.makeUriById(BuildConfig.APPLICATION_ID, R.mipmap.ic_launcher)
    val URI_TEST_ANDR_RES_BY_NAME3 = AndroidResUriModel.makeUriByName("com.android.settings", "drawable", "ic_launcher")
    val URI_TEST_APP = AppIconUriModel.makeUri(BuildConfig.APPLICATION_ID, BuildConfig.VERSION_CODE)
    const val URI_TEST_ASSET = "asset://mei_nv.jpg"
    val URI_TEST_DRAWABLE = DrawableUriModel.makeUri(R.mipmap.ic_launcher)

    val IN_BITMAP_SAMPLES = arrayOf(TYPE_TEST_JPG, TYPE_TEST_PNG, TYPE_TEST_GIF, TYPE_TEST_WEBP, TYPE_TEST_BMP)

    val HUGE_IMAGES = arrayOf(HUGE_WORLD_MAP, HUGE_QMSHT, HUGE_CHANG_WEI_BO, HUGE_CARD)
    const val URI_TEST_BASE64 = ""

    fun getAll(context: Context): Array<String> {
        val stringList = ArrayList<String>()
        Collections.addAll(stringList, TYPE_TEST_JPG,
                TYPE_TEST_PNG,
                TYPE_TEST_GIF,
                TYPE_TEST_WEBP,
                TYPE_TEST_BMP,

                HUGE_WORLD_MAP,
                HUGE_QMSHT,
                HUGE_CHANG_WEI_BO,
                HUGE_CARD,

                MEI_NV,
                MASK,
                CHUNK,
                CHUNK2)
        Collections.addAll(stringList, *getTestUris(context))
        return stringList.toTypedArray()
    }

    fun getTestUris(context: Context): Array<String> {
        return try {
            arrayOf(URI_TEST_ASSET, URI_TEST_APP, ApkIconUriModel.makeUri(context.packageManager.getApplicationInfo(context.packageName, 0).sourceDir), URI_TEST_ANDR_RES_BY_NAME, URI_TEST_ANDR_RES_BY_NAME2, URI_TEST_ANDR_RES_BY_ID, URI_TEST_ANDR_RES_BY_NAME3, URI_TEST_BASE64, URI_TEST_DRAWABLE)
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
            arrayOf()
        }
    }
}
